package br.inf.solutions.apresentacoes.ssp.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.vexillum.model.annotations.NotInitialize;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.com.vexillum.util.HibernateUtils;
import br.inf.solutions.apresentacoes.ssp.model.basics.BasicCommon;

@Entity
@ValidatorClass(validatorClass="br.inf.solutions.apresentacoes.ssp.control.validator.PostGraduationValidator")
@SuppressWarnings("serial")
public class PostGraduation extends BasicCommon {

	@Column(nullable=false)
	@Validate(notNull=true)
	private String acronym;

	@Validate(notNull=true)
	@NotInitialize
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pattern_id", insertable = true, updatable = true, nullable=true)
	private PostGraduation pattern;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pattern")
	private List<PostGraduation> childrens;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "circle_herarchical_id", insertable = true, updatable = true, nullable=true)
	private CircleHierarchical circleHierarchical;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "postGraduation")
	private List<Requeriment> requiriments;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "postGraduation",targetEntity=SquarePostGraduation.class,orphanRemoval=true)
	@Cascade(value = {CascadeType.MERGE})
	private List<SquarePostGraduation> squarePostAssociations;
	
	@Transient
	private Long numberEffective;
	
	public Long getNumberEffective() {
		return numberEffective;
	}

	public void setNumberEffective(Long numberEffective) {
		this.numberEffective = numberEffective;
	}

	public String getAcronym() {
		return acronym;
	}

	public void setAcronym(String acronym) {
		this.acronym = acronym;
	}

	public PostGraduation getPattern() {
		return pattern;
	}

	public void setPattern(PostGraduation pattern) {
		this.pattern = pattern;
	}

	public List<PostGraduation> getChildrens() {
		return childrens;
	}

	public void setChildrens(List<PostGraduation> childrens) {
		this.childrens = childrens;
	}

	public CircleHierarchical getCircleHierarchical() {
		return circleHierarchical;
	}

	public void setCircleHierarchical(CircleHierarchical circleHierarchical) {
		this.circleHierarchical = circleHierarchical;
	}

	public List<Requeriment> getRequiriments() {
		return requiriments;
	}

	public void setRequiriments(List<Requeriment> requiriments) {
		this.requiriments = requiriments;
	}

	public List<SquarePostGraduation> getSquarePostAssociations() {
		return squarePostAssociations;
	}

	public void setSquarePostAssociations(
			List<SquarePostGraduation> squarePostAssociations) {
		this.squarePostAssociations = squarePostAssociations;
	}
	
	@Override
	public String toString() {
		return getName();
	}
	
	public boolean equals(PostGraduation obj) {
		if(obj == null) return false;
		obj = HibernateUtils.materializeProxy(obj);
		if(obj.getId().equals(this.getId())){
			return true;
		}
		return false;
	}

}
